﻿using System;
using System.Collections.Generic;
using System.Text;
using AnguaRPGEngine.Library.Configuration;
using System.IO;
using AnguaRPGEngine.Library.Events;
using AnguaRPGEngine.Library.Events.Messages;

namespace AnguaRPGEngine.Library.Systems
{
    public class GameSystem
    {
        public static GameSystem Instance = new GameSystem();
        public bool IsShuttingDown = false;
        public bool IsGMClient;
        public ClientConfiguration ClientConfig;
        public bool ResizeOn = false;
        public bool CaptionHit = false;
        public string ConfigurationFSpec
        {
            get
            {
                if (IsGMClient)
                {
                    return PathToData + "GMClient.cfg";
                }
                else
                {
                    return PathToData + "PCClient.cfg";
                }
            }
        }
        public string PathToData
        {
            get
            {
#if DEBUG
                string p = Directory.GetCurrentDirectory();
                if (p.IndexOf("AnguaRPGEngine.") > -1)
                {
                    p = p.Substring(0, p.IndexOf("AnguaRPGEngine.")) + "Assets\\Data\\";
                }
                else if(p.IndexOf("TestingSandBox.") > -1)
                {
                    p = p.Substring(0, p.IndexOf("TestingSandBox")) + "Assets\\Data\\";
                }
                return p;
#else
                return @"C:\AnguaRPGEngine\Data\";
#endif
            }
        }
        public string PathToDLLs
        {
            get
            {
                return PathToData + @"DLLs\";
            }
        }
        public GameSystem()
        {

        }
        public void Initialize(bool IsGM)
        {
            this.IsShuttingDown = false;
            this.IsGMClient = IsGM;
            this.ClientConfig = ClientConfiguration.LoadClientConfiguration();
            if (this.ClientConfig == null)
            {
                this.ClientConfig = new ClientConfiguration();
                this.ClientConfig.FormPositions = new List<FormPosition>();
            }
            ApplicationController.EventAggregator.RegisterListener(this);
        }
        public void SaveConfiguration()
        {
            ClientConfiguration.SaveClientConfiguration(this.ClientConfig);
        }
        public void Shutdown()
        {
            ClientConfiguration.SaveClientConfiguration(this.ClientConfig);
        }
        public List<PlayerPCPair> GetPossiblePlayerPCPairs()
        {
            return new List<PlayerPCPair>();
        }
    }
}
